{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}

<div class="p-3">
	<form class="layui-form gg-form-bar border-t border-x">
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" name="keywords" placeholder="请输入名称或手机号关键字" class="layui-input" autocomplete="off" />
		</div>
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="searchform">提交搜索</button>
	</form>
	<table class="layui-hide" id="user_two" lay-filter="user_two"></table>
</div>

<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<span class="layui-btn layui-btn-sm" lay-event="add" data-title="添加售酒机管理员">+ 添加售酒机管理员</span>
	</div>
</script>

<script type="text/html" id="barDemo">
<div class="layui-btn-group">
	<a class="layui-btn layui-bg-1 layui-btn-xs" lay-event="shou">收益明细</a>
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a><a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a></div>
</script>
<script type="text/html" id="image">
	<img src="{{d.image}}" width="30" height="30" lay-event="image"/>
</script>
<script type="text/html" id="imagesArr">
	{{# if(d.images != ''){ }}
	{{# layui.each(d.images, function(index, item){ }}
	<img src="{{item}}" width="30" height="30"  lay-event="image"/>
	{{# }); }}
	{{# }else{}}
	暂无图片
	{{#}}}
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table,tool = layui.tool, form = layui.form;
		layui.pageTable = table.render({
			elem: '#user_two',
			title: '售酒机管理员列表',
			toolbar: '#toolbarDemo',
			url: '/admin/user_two/datalist',
			page: true,
			limit: 20,
			lineStyle:'height:auto',
			cellMinWidth: 60,
			cols: [
				[
				{
					// fixed: 'left',
					field: 'id',
					title: 'ID',
					align: 'center',
					width: 80
				},{
                        field: 'user_name',
                        title: '名称',
                        align: 'center',
					width: 220,
                    },{
                        field: 'mobile',
                        title: '手机号',
                        align: 'center',
					width: 220,
                    }, {
						field: 'status',
						title: '状态',
						align: 'center',
						width: 150,
						templet: function (d) {
							var str = "";
							if (d.status == 1) {
								str = '<span style="color: #5FB878">正常</span>';
							} else {
								str = '<span style="color: red">禁用</span>';
							}
							return str;
						},
					},{
                        field: 'wallet',
                        title: '收益',
                        align: 'center',
					width: 150,
                    },{
                        field: 'create_time',
                        title: '创建时间',
                        align: 'center',
					width: 150,
                    },
				{
					field: 'right',
					title: '操作',
					toolbar: '#barDemo',
					width: 186,
					align: 'center'
				}				
				]
			]
		});
		
		//监听表头工具栏事件
		table.on('toolbar(user_two)', function(obj){
			if (obj.event === 'add') {
				tool.side("/admin/user_two/add");
				return false;
			}
		});

		//监听表格行工具事件
		table.on('tool(user_two)', function(obj) {
			var data = obj.data;
			if (obj.event === 'read') {
				tool.side('/admin/user_two/read?id='+obj.data.id);
			}
			else if (obj.event === 'edit') {
				tool.side('/admin/user_two/edit?id='+obj.data.id);
			}
			else if (obj.event === 'shou') {
				tool.side('/admin/wallet_log/datalist?type=2&id='+obj.data.id);
			}
			else if (obj.event === 'del') {
				layer.confirm('确定要删除该记录吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/admin/user_two/del", { id: data.id }, callback);
					layer.close(index);
				});
			}
			if(obj.event === 'image')
			{
				var src = $(this).attr('src');
				// 在此处输入 layer 的任意代码
				layer.open({
					type: 1, // page 层类型
					area: ['500px', '500px'],
					title: '',
					shade: 0.6, // 遮罩透明度
					shadeClose: true, // 点击遮罩区域，关闭弹层
					maxmin: true, // 允许全屏最小化
					anim: 0, // 0-6 的动画形式，-1 不开启
					content: "<img src="+src+" style='width: 100%;'>"
				});
			}
			return false;
		});

		//监听搜索提交
		form.on('submit(searchform)', function(data) {
			layui.pageTable.reload({
				where: {
					keywords: data.field.keywords
				},
				page: {
					curr: 1
				}
			});
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->